﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ViewBindable.cs" company="">
//   
// </copyright>
// <summary>
//   The view bindable.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.UseCases
{
    using System;

    /// <summary>
    ///   The view bindable.
    /// </summary>
    public abstract class ViewBindable : IViewBindable
    {
        #region Fields

        /// <summary>
        ///   The _enabled.
        /// </summary>
        protected bool _enabled = true;

        #endregion

        #region Public Events

        /// <summary>
        ///   The enabled changed.
        /// </summary>
        public event Action<IViewBindable> EnabledChanged;

        /// <summary>
        ///   The unavailable.
        /// </summary>
        public event Action<IViewBindable> Unavailable;

        #endregion

        #region Public Properties

        /// <summary>
        ///   Gets or sets a value indicating whether enabled.
        /// </summary>
        public virtual bool Enabled
        {
            get
            {
                return _enabled;
            }

            set
            {
                if (_enabled == value)
                {
                    return;
                }

                _enabled = value;
                OnEnabledChanged();
            }
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///   The raise on unavailable.
        /// </summary>
        public void RaiseOnUnavailable()
        {
            if (Unavailable != null)
            {
                Unavailable(this);
            }
        }

        #endregion

        #region Methods

        /// <summary>
        ///   The on enabled changed.
        /// </summary>
        protected virtual void OnEnabledChanged()
        {
            if (EnabledChanged != null)
            {
                EnabledChanged(this);
            }
        }

        #endregion
    }
}